package main.java.com.util;

import java.io.InputStream;
import java.util.Properties;

/**
 * !!! Anti-fake label !!!
 * ClassName: PropertiesRead
 * Package: main.java.com.util
 * Description:
 *
 * @Author 22软件6班 陈彬
 * @Create 2023/11/1 8:15
 * @Version 1.0
 **/
public class PropertiesRead {
    public static void main(String[] args) {
        try {
            //创建properties属性文件对象
            Properties properties = new Properties();
            //将db.properties文件读取到输入流中
            InputStream is = PropertiesRead.class.getClassLoader().getResourceAsStream("db.properties");
            //将文件流加载到properties对象中
            properties.load(is);
            //获取用户名
            String dbUser = properties.getProperty("DB_USER");
            //获取密码
            String dbPassword = properties.getProperty("DB_PASSWORD");
            System.out.println("用户名："+dbUser);
            System.out.println("密码："+dbPassword);


        }catch (Exception e) {
            e.printStackTrace();//打印错误信息
        }
    }
}
